package inits

import (
	"flag"
	"gateway/basic/config"
	"gateway/untils"
	"github.com/google/uuid"
	"log"

	__ "gateway/basic/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func InitGrpc() {
	client, err := untils.NewConfigClient("14.103.175.154:8500")
	if err != nil {
		panic("init consul failed:" + err.Error())
	}
	consul := untils.Consul{
		ID:      uuid.NewString(),
		Name:    "hospital",
		Tags:    []string{"hospital"},
		Port:    8888,
		Address: "127.0.0.1",
	}
	client.RegisterService(consul)
	flag.Parse()
	// Set up a connection to the server.
	conn, err := grpc.NewClient("127.0.0.1:8083", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}

	config.HospitalClient = __.NewHospitalClient(conn)

}
